<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Add a high priority task to run in parallel</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="gearmanclient.addtaskbackground.html">GearmanClient::addTaskBackground</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="gearmanclient.addtaskhighbackground.html">GearmanClient::addTaskHighBackground</a></div>
 <div class="up"><a href="class.gearmanclient.html">GearmanClient</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="gearmanclient.addtaskhigh" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">GearmanClient::addTaskHigh</h1>
  <p class="verinfo">(PECL gearman &gt;= 0.5.0)</p><p class="refpurpose"><span class="refname">GearmanClient::addTaskHigh</span> &mdash; <span class="dc-title">Add a high priority task to run in parallel</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-gearmanclient.addtaskhigh-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="type"><a href="class.gearmantask.html" class="type GearmanTask">GearmanTask</a></span> <span class="methodname"><strong>GearmanClient::addTaskHigh</strong></span>
    ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$function_name</code></span>
   , <span class="methodparam"><span class="type">string</span> <code class="parameter">$workload</code></span>
   [, <span class="methodparam"><span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span> <code class="parameter reference">&$context</code></span>
   [, <span class="methodparam"><span class="type">string</span> <code class="parameter">$unique</code></span>
  ]] )</div>

  <p class="para rdfs-comment">
   Adds a high priority task to be run in parallel with other tasks.  Call this method for all
   the high priority tasks to be run in parallel, then call
   <span class="methodname"><a href="gearmanclient.runtasks.html" class="methodname">GearmanClient::runTasks()</a></span> to perform the work.  Tasks with a high
   priority will be selected from the queue before those of normal or low priority.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-gearmanclient.addtaskhigh-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>

    
     <dt>
<em><code class="parameter">function_name</code></em></dt>

     <dd>

      <p class="para">
       由程序自动执行的已注册函数。
      </p>
     </dd>

    
    
     <dt>
<em><code class="parameter">workload</code></em></dt>

     <dd>

      <p class="para">
       被处理的序列化数据。
      </p>
     </dd>

    
    
     <dt>
<em><code class="parameter">context</code></em></dt>

     <dd>

      <p class="para">
       与任务关联的应用程序上下文。
      </p>
     </dd>

    
    
     <dt>
<em><code class="parameter">unique</code></em></dt>

     <dd>

      <p class="para">
       用于标识特定任务的唯一性 ID。
      </p>
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-gearmanclient.addtaskhigh-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   A <a href="class.gearmantask.html" class="classname">GearmanTask</a> object or <strong><code>FALSE</code></strong> if the task could not be added.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-gearmanclient.addtaskhigh-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-4225">
    <p><strong>Example #1 A high priority task along with two normal tasks</strong></p>
    <div class="example-contents"><p>
     A high priority task is included among two other tasks.  A single worker
     is available, so that tasks are run one at a time, with the high priority
     task run first.
    </p></div>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /><br /></span><span style="color: #FF8000">#&nbsp;create&nbsp;the&nbsp;gearman&nbsp;client<br /></span><span style="color: #0000BB">$gmc</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">GearmanClient</span><span style="color: #007700">();<br /><br /></span><span style="color: #FF8000">#&nbsp;add&nbsp;the&nbsp;default&nbsp;job&nbsp;server<br /></span><span style="color: #0000BB">$gmc</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">addServer</span><span style="color: #007700">();<br /><br /></span><span style="color: #FF8000">#&nbsp;set&nbsp;the&nbsp;callback&nbsp;for&nbsp;when&nbsp;the&nbsp;job&nbsp;is&nbsp;complete<br /></span><span style="color: #0000BB">$gmc</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">setCompleteCallback</span><span style="color: #007700">(</span><span style="color: #DD0000">"reverse_complete"</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">#&nbsp;add&nbsp;tasks,&nbsp;one&nbsp;of&nbsp;which&nbsp;is&nbsp;high&nbsp;priority<br /></span><span style="color: #0000BB">$task</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$gmc</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">addTask</span><span style="color: #007700">(</span><span style="color: #DD0000">"reverse"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"Hello&nbsp;World!"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">null</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"1"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$task</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$gmc</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">addTaskHigh</span><span style="color: #007700">(</span><span style="color: #DD0000">"reverse"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"!dlroW&nbsp;olleH"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">null</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"2"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$task</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$gmc</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">addTask</span><span style="color: #007700">(</span><span style="color: #DD0000">"reverse"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"Hello&nbsp;World!"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">null</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"3"</span><span style="color: #007700">);<br /><br />if&nbsp;(!&nbsp;</span><span style="color: #0000BB">$gmc</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">runTasks</span><span style="color: #007700">())<br />{<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"ERROR&nbsp;"&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">$gmc</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">error</span><span style="color: #007700">()&nbsp;.&nbsp;</span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;exit;<br />}<br />echo&nbsp;</span><span style="color: #DD0000">"DONE\n"</span><span style="color: #007700">;<br /><br />function&nbsp;</span><span style="color: #0000BB">reverse_complete</span><span style="color: #007700">(</span><span style="color: #0000BB">$task</span><span style="color: #007700">)<br />{<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"COMPLETE:&nbsp;"&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">$task</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">unique</span><span style="color: #007700">()&nbsp;.&nbsp;</span><span style="color: #DD0000">",&nbsp;"&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">$task</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">data</span><span style="color: #007700">()&nbsp;.&nbsp;</span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br />}<br /><br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

    <div class="example-contents"><p>以上例程的输出类似于：</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
COMPLETE: 2, Hello World!
COMPLETE: 3, !dlroW olleH
COMPLETE: 1, !dlroW olleH
DONE
</pre></div>
    </div>
   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-gearmanclient.addtaskhigh-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="methodname"><a href="gearmanclient.addtask.html" class="methodname" rel="rdfs-seeAlso">GearmanClient::addTask()</a> - Add a task to be run in parallel</span></li>
    <li class="member"><span class="methodname"><a href="gearmanclient.addtasklow.html" class="methodname" rel="rdfs-seeAlso">GearmanClient::addTaskLow()</a> - Add a low priority task to run in parallel</span></li>
    <li class="member"><span class="methodname"><a href="gearmanclient.addtaskbackground.html" class="methodname" rel="rdfs-seeAlso">GearmanClient::addTaskBackground()</a> - Add a background task to be run in parallel</span></li>
    <li class="member"><span class="methodname"><a href="gearmanclient.addtaskhighbackground.html" class="methodname" rel="rdfs-seeAlso">GearmanClient::addTaskHighBackground()</a> - Add a high priority background task to be run in parallel</span></li>
    <li class="member"><span class="methodname"><a href="gearmanclient.addtasklowbackground.html" class="methodname" rel="rdfs-seeAlso">GearmanClient::addTaskLowBackground()</a> - Add a low priority background task to be run in parallel</span></li>
    <li class="member"><span class="methodname"><a href="gearmanclient.runtasks.html" class="methodname" rel="rdfs-seeAlso">GearmanClient::runTasks()</a> - Run a list of tasks in parallel</span></li>
   </ul>
  </p>
 </div>


</div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="gearmanclient.addtaskbackground.html">GearmanClient::addTaskBackground</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="gearmanclient.addtaskhighbackground.html">GearmanClient::addTaskHighBackground</a></div>
 <div class="up"><a href="class.gearmanclient.html">GearmanClient</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>
